Dashboard Temp Share Shortlinks Frames API

HTMLify

Move Zeros To Left
Views: 1 | Author: cody
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <bits/stdc++.h> 
void moveZerosToLeft(int *arr, int n) 
{

      int i=n-1;    
      for(int j=n-1;j>=0;j--){        
          if(arr[j]!=0){            
              swap(arr[i],arr[j]);            
              i--;        
            }    
        }

    }